﻿<%@ Page Title="" Language="C#" MasterPageFile="~/web/common/Common.Master" AutoEventWireup="true" CodeBehind="GoodDetail.aspx.cs" Inherits="shop.web.view.GoodDetail" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>商品详情</title>
    <link href="../css/main.css" rel="stylesheet" />
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="layui-container ">
        <%if (goods != null)
            {
        %>

        <div class="goods-img ">
            <img src="../resource/img<%=goods.Image.ImagePath %>" alt="Alternate Text" />
        </div>
        <div class="goods-info good-wrap">

            <div>
                <span class="">商品名称：
                </span>

                <span class="name">
                    <%=goods.Name %>
                </span>
            </div>
            <div>
                <span>商品描述：
                </span>
                <span class="description">
                    <%=goods.Description%>
                </span>
            </div>

            <div>
                <span>商品价格：
                </span>
                <span class="price">
                    <%=goods.Price %>元
                </span>
            </div>
            <div class="action">
                <a class="add" href="#">
                    <img src="../resource/img/system/btn_addcart.gif" />
                </a>
                <a href="javascript:;" class="buy">
                    <img src="../resource/img/system/btn_tobuy.gif" />

                </a>

            </div>
        </div>

        <%
            }
            else
            {
        %>
        未找到该商品！！
        <%
            }
        %>
    </div>
    <script>
        var logined = <% = logined %>;

        function addOrder(order) {
            $.ajax({
                url: "/handler/OrderHandler.ashx",
                type: "post",
                data: order,
                success: function (data) {
                    layer.msg(data);
                }
            })
        }

        layui.use(['element', 'layer'], function () {
            var layer = layui.layer;
            var msg = "输入登录密码";
            $(".add").click(function () {
                if (!logined) {
                    layer.msg("请先登录！", { icon: 0 }, function () {
                        window.location.href = "/web/view_admin/user/Login.aspx"
                    })
                    return;
                }
                 layer.msg("购物模块未做，点击立即购买，可以立即下单！", { icon: 0 })
            })

            $(".buy").click(function () {
                if (!logined) {
                    layer.msg("请先登录！", { icon: 0 }, function () {
                        window.location.href = "/web/view_admin/user/Login.aspx"
                    })
                    return;
                }

                var passsword =  <% = password %>;
                var userId = 0;
                if (logined) {
                    userId = <%=userId%>;
                }
                layer.prompt({
                    formType: 1,
                    title: '请输入支付密码（此处模拟输入登录密码）',
                }, function (value, index, elem) {
                    if (value == passsword) {
                        layer.msg("支付成功，正在下单...", { icon: 6 }, function () {

                            addOrder({
                                userId: userId,
                                goodsId:  <%=goods.Id%>,
                                    method: "add"
                                });
                                layer.close(index);
                            });
                        } else {
                            layer.msg("支付失败,支付密码错误！", { icon: 2 })
                        }

                    });
            })
        })

    </script>
</asp:Content>
